﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;


namespace Taxes.KML
{
    public partial class KMLImport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [DirectMethod]
        public void DeleteFile(string fileName, string fileClientName)
        {
            try
            {
                System.IO.File.Delete(fileName);
                //X.Msg.Notify("提示", fileClientName + "已删除!").Show();
            }
            catch (Exception ex)
            {
                //X.Msg.Notify("提示", fileClientName + "删除失败!").Show();
            }
        }
        [DirectMethod]
        public void Up(string att)
        {
            var path = System.Configuration.ConfigurationManager.AppSettings["UploadPath"].ToString();
            var fileName = Server.MapPath(path + "/" + att);

            var kml = new KMLOperate(fileName);

            var regions =  kml.GetRegion();
            var bll = new BLL.region_info();
            if (bll.DeleteAll())
            {
                foreach (var r in regions)
                {
                    var model = new Model.region_info()
                    {
                        region_name = r.Name,
                        region_unit_price = (decimal)r.Cost,
                        region_value = r.Postion
                    };
                    bll.Add(model);
                }


                var bllRevenue_info = new BLL.revenue_info();
                var revenes = bllRevenue_info.GetModelList("");
                foreach (var r in revenes)
                {
                    if (r.reve_lon != 0 && r.reve_lat != 0)
                    {
                        ///不为零重新计算经纬度
                         bllRevenue_info.GetRegionID(r.reve_lon, r.reve_lat,r.ID);
                    }
                }
            }
            Response.Redirect("UnitAreaRecent.aspx");
        }
    }
}